﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
	</head>
	<body>
		<div id="app">
			<!--直接给出指令的参数-->
			<p v-pin:top="100">
				Java无难事
			</p>
			<!--使用动态参数-->
			<p v-pin:[direction]="100">
				Java无难事
			</p>
		</div>
	
		<script src="https://unpkg.com/vue@next"></script>
		<script>
		    const app = Vue.createApp({
		        data() {
    			    return {
    			        direction: 'left'
    			    }
			    }
		    })
			app.directive('pin', {
			  beforeMount(el, binding, vnode) {
			  	el.style.position = 'fixed';
			  	let s = binding.arg || 'left';
	    		el.style[s] = binding.value + 'px'
			  }
			})
			app.mount('#app')
		</script>
	</body>
</html>